
var config = require('config');
var log4js = require('log4js');

/*
 * 【BAE扩展服务：log】使用BAE的log sdk, 日志持久化
 */
/*
log4js.loadAppender('baev3-log');
var options = {
 "user": config.get('credentials.ak'),
 "passwd": config.get('credentials.sk')
};

log4js.addAppender(log4js.appenders['baev3-log'](options));
var logger = log4js.getLogger('node-log-sdk');
logger.setLevel('DEBUG');

exports.logger = logger;
exports.use = function(app) {
    app.use(log4js.connectLogger(logger, {level:'debug', format:':method :url'}));
};
*/
/*
 * 配置本地日志
 */
log4js.configure({
    appenders: [
        {
            type: 'console',
            category: "console"
        },
        {
            type: "dateFile",
            filename: config.get('logdir')+'console.log',
            pattern: "_yyyy-MM-dd",
            alwaysIncludePattern: false,
            category: 'dateFileLog'
        }
    ],
    replaceConsole: true,
    levels:{
        dateFileLog: 'INFO'
    }
});

var dateFileLog = log4js.getLogger('dateFileLog');
exports.logger = dateFileLog;
exports.use = function(app) {
    app.use(log4js.connectLogger(dateFileLog, {level:'auto', format:':method :url'}));
};
